Skip to content

fix(go): a coalesced leader keeps a value returned with an error - #277

Merged
lan17 merged 2 commits into
mainfrom
fix/go-shadow-fill-and-value-with-error
Nov 14, 2026
Merged

lan17 merged 2 commits into
mainfrom
fix/go-shadow-fill-and-value-with-error

Conversation

@lan17

@lan17 lan17 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Problem

A Go loader can return a value together with an error. Without coalescing, GetOrLoad returns both. With coalescing on, the caller that leads the flight now gets only the error: since the leader runs its work in a goroutine (#255), it reads the settled result the same way a follower does, and followerResult drops the value when there is an error. v0.27.0 returned both to the leader. Reported in the Follow-ups of #274. The other item there, a dark-shadow fill after an invalidation, needs no change: futureBufferMs ≥ Dmax covers it, as it covers a normal refill, and TypeScript behaves the same.

Change

Bug fix (restored behavior). After its wait, the leader returns the value that its work returned together with the error. Followers still get only the error, as in v0.27.0. A value of another type under the same key still gives the zero value. No design record and no docs change: the behavior returns to v0.27.0.

Mutant M20 is re-anchored to the new leader code with the same fault, and the go/engine.go pins in go-parity.json are re-pinned (the TypeScript mapping is unchanged: TypeScript throws and returns no value with an error).

Ports

Port Status
TypeScript N/A: a loader error is thrown, so there is no value with it
Go done
Rust N/A: a loader returns a Result
Python N/A: a loader error is raised

Validation

Head: df05cc6

  • New test TestCoalescedLeaderKeepsAValueReturnedWithAnError in go/flight_lifetime_test.go, for process and request-local coalescing: the leader gets (7, err), a follower gets (0, err), and the value is not cached. It fails at 22c1f50 (the leader gets (0, err)) and on a mutant where followers also get the value, and passes at df05cc6 (-race -count=3).
  • Review-loop and rollout-safety on d5887b0: no blocker; both asked for the follower test above, added in df05cc6.
  • make check-go, make formal-generate and make formal-go at d5887b0: pass (df05cc6 changes only the test). make audit at df05cc6: pass.
  • The lifetime, follower and cancellation tests in go/flight_lifetime_test.go under -race: pass.
  • PR CI at df05cc6: every check passes (a Codecov upload failure was re-run).
  • formal-full.yaml in mutations mode at df05cc6: run 43485734239, pass, 37 of 37 jobs (replay in all four ports, symbolic lane, and the TypeScript, Go and Rust mutation campaigns).

Not run: none.

Follow-ups

None.

Since the leader runs its work in a goroutine, it read its result as a
follower and dropped a value that the loader returned together with an
error. v0.27.0 and the uncoalesced path return both. The leader now
returns the value with the error again; followers still get only the
error.
@codecov-commenter

codecov-commenter commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.77%. Comparing base (22c1f50) to head (df05cc6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #277   +/-   ##
=======================================
  Coverage   94.76%   94.77%           
=======================================
  Files          84       84           
  Lines       13168    13171    +3     
  Branches      805      805           
=======================================
+ Hits        12479    12483    +4     
+ Misses        623      622    -1     
  Partials       66       66           
Flag Coverage Δ
go 93.91% <100.00%> (+0.04%) ⬆️
python 93.60% <ø> (ø)
rust 94.78% <ø> (ø)
typescript 97.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lan17 lan17 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent: Review of head d5887b0 (one commit on main 22c1f50) in report mode. Lanes: correctness, tests, contracts, simplicity and holistic. The holistic lane made an independent pass first, then audited the findings. Concurrency, reliability, performance, security and architecture do not apply: the change is a 6-line return path that reads the settled flight after f.done. This is a comment review. It does not approve and does not request changes.

Verdict: no blocker, no high and no medium. 1 low test gap. The code meets the PR's goal. The correctness, contracts and simplicity lanes found no issue.

ID Severity Tag Location Fix
R5-F1 low V go/flight_lifetime_test.go:576 Add a leader-and-follower test: the leader gets (7, err) and the follower gets (0, err), for Policy{} and Policy{RequestLocal: true}.

Tag V: we ran it or read the code at the head. R5-F1 has an inline comment.

What we checked:

  • TestCoalescedLeaderKeepsAValueReturnedWithAnError fails at 22c1f50 (leader = (0, partial result)) and passes at d5887b0.
  • With a gated loader that returns (7, err) and a follower that joins before release, the head gives leader (7, err) and follower (0, err), for both process and request-local coalescing. This matches go/v0.27.0, where the leader ran the work inline and returned both values.
  • A request-local leader keeps the value only when its request also led the process flight. When it joins another request's process flight, it gets (0, err), as a follower does. This also matches v0.27.0.
  • The caller's own cancellation still wins before the new branch. A timeout, a panic and a stale recovery are unchanged: zero value with the error, or the stale value with no error. An error result still fills no cache.
  • Every go/engine.go before anchor in formal/catalogs/mutations.json occurs exactly once in go/engine.go at the head.

Not re-run here: the replay and effects conformance tests (Node is not installed in our sandbox), the Mutations run (pending on the final head by design) and make check-go, formal-go and audit. We take those as reported.

— Levicus Connecto 🤖

Comment thread go/flight_lifetime_test.go Outdated
ctx, done := f.cache.Enable(context.Background())
defer done()
failed := errors.New("partial result")
if v, err := f.get(ctx, func(context.Context) (int, error) { return 7, failed }); v != 7 || !errors.Is(err, failed) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent: R5-F1 (low, V). No test checks that followers still get only the error.

This test makes one call, so it covers the leader only. The other tests with a loader error return a zero value, so they cannot tell a follower's (0, err) from (7, err). A mutant where followerResult also returns the value with the error passes every Go test that runs in our sandbox. The test below catches it (follower=(7, partial result)). The code at the head is correct: this test passes for both policies.

func TestCoalescedFollowerGetsOnlyTheErrorOfAValueWithAnError(t *testing.T) {
	for _, policy := range []Policy{{}, {RequestLocal: true}} {
		synctest.Test(t, func(t *testing.T) {
			f := newLifetimeFixture(policy)
			ctx, done := f.cache.Enable(context.Background())
			defer done()
			failed := errors.New("partial result")
			release := make(chan struct{})
			load := func(context.Context) (int, error) { <-release; return 7, failed }
			type result struct {
				v   int
				err error
			}
			leader, follower := make(chan result, 1), make(chan result, 1)
			go func() { v, err := f.get(ctx, load); leader <- result{v, err} }()
			synctest.Wait()
			go func() { v, err := f.get(ctx, load); follower <- result{v, err} }()
			synctest.Wait()
			close(release)
			l, fo := <-leader, <-follower
			if l.v != 7 || !errors.Is(l.err, failed) || fo.v != 0 || !errors.Is(fo.err, failed) {
				t.Fatalf("leader = (%d, %v), follower = (%d, %v); want (7, err) and (0, err)", l.v, l.err, fo.v, fo.err)
			}
		})
	}
}

Low, because followerResult does not change in this PR. The test guards the leader and follower split against a later change.

— Levicus Connecto 🤖

@lan17 lan17 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent: Rollout-safety review of head d5887b0 (report mode, comment only; the PR is a draft). Scope: the code commit only.

Verdict: no blocker. The change is safe to merge and to release. I found one low test gap and two gates that are not code defects.

Why it is safe

  • The new branch runs only for the leader, only after its own context check, and only when the work failed (go/engine.go:279-291). Followers still go through followerResult (go/engine.go:292).
  • The value is the leader's own work result. The flight goroutine writes f.value and f.err from callSafely[T] before close(f.done) (go/engine.go:260, :272). So the read is race-free, the type is always T, and a panic gives the zero value.
  • Only a loader's own pair reaches this branch. traverse returns v, err from the source before any fill (go/engine.go:442-450). Timeouts, context errors and panics carry zero values.
  • I measured with a scratch test under -race. With coalescing on: the leader gets (7, err), the follower gets (0, err), and the next call runs the source again with no remote write of 7. With coalescing off, both callers get (7, err). With request-local coalescing, the leader gets (7, err) and the follower (0, err). This matches v0.27.0, where the leader returned value, err from its inline run.
  • No release exists after v0.27.0, so released callers see no change.
  • Every Go before anchor in mutations.json matches the head exactly once (82), M20 included.
  • Local, Go 1.27.1, -race: the new test fails at 22c1f50 ("leader = (0, partial result)") and passes at the head. The lifetime tests and ./internal/testsuite pass with -count=3, and the native go test -race . tests and go vet ./... pass.

Findings

ID Severity Tag Where Issue Fix
T1 low V go/flight_lifetime_test.go:570-579 The test pins only the leader. Nothing pins the PR's claim that followers get only the error, or that a value returned with an error is not cached. A mutant where followerResult also returns the value passes every native Go test. Add the follower test in the inline comment. It passes at the head with -race -count=3 and fails on that mutant ("follower = (7, partial result)").
G1 gate (CI) V CI run 43361613506, jobs typescript and python / native (3.14) Both jobs' tests passed, but the Codecov upload failed: "gpg: no valid OpenPGP data found", then "Could not verify signature". So the required test check is red on d5887b0. The rust job on #274 failed the same way in run 43324223350, so this failure repeats. Re-run: gh run rerun 43361613506 --failed. If it fails again, a separate tooling change can stop the Codecov upload from failing the job.
G2 gate V formal/catalogs/mutations.json (M20) The PR edits the mutation catalog, so the Mutations tier must pass before the PR leaves draft. No formal-full.yaml run exists for this branch yet. The description already plans one on the final head. Run formal-full.yaml in mutations mode on the final head.

Note: with request-local coalescing, a request whose work joins another request's process flight is a follower there, so its leader gets only the error. This matches the follower rule and needs no change.

— Levicus Connecto 🤖

})
}

func TestCoalescedLeaderKeepsAValueReturnedWithAnError(t *testing.T) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent: T1 (low, V). This test pins only the leader. Suggested companion test: it pins that followers get only the error, and that a value returned with an error is not cached. It passes at d5887b0 with -race -count=3. It fails on a mutant where followerResult also returns the value ("follower = (7, partial result), want (0, partial result)"), and no native test catches that mutant today.

func TestCoalescedFollowerGetsOnlyTheErrorAndNothingIsCached(t *testing.T) {
	synctest.Test(t, func(t *testing.T) {
		f := newLifetimeFixture(Policy{LocalTTL: time.Minute})
		ctx, done := f.cache.Enable(context.Background())
		defer done()
		failed := errors.New("partial result")
		gate := make(chan struct{})
		load := func(context.Context) (int, error) { f.calls.Add(1); <-gate; return 7, failed }
		leader := make(chan int, 1)
		go func() { v, _ := f.get(ctx, load); leader <- v }()
		synctest.Wait()
		var fv int
		follower := make(chan error, 1)
		go func() { v, err := f.get(ctx, load); fv = v; follower <- err }()
		synctest.Wait()
		close(gate)
		if v := <-leader; v != 7 {
			t.Fatalf("leader value = %d, want 7", v)
		}
		if err := <-follower; fv != 0 || !errors.Is(err, failed) {
			t.Fatalf("follower = (%d, %v), want (0, %v)", fv, err, failed)
		}
		if v, err := f.get(ctx, func(context.Context) (int, error) { f.calls.Add(1); return 9, nil }); v != 9 || err != nil || f.calls.Load() != 2 {
			t.Fatalf("next call = (%d, %v) after %d source calls; want (9, nil) after 2: a value returned with an error is not cached", v, err, f.calls.Load())
		}
	})
}

— Levicus Connecto 🤖

The leader test covered one caller. Followers of a value returned with an
error still get only the error, and the value is not cached, for process
and request-local coalescing.
@lan17
lan17 marked this pull request as ready for review November 13, 2026 19:40
@lan17
lan17 merged commit 60c1453 into main Nov 14, 2026
61 checks passed
@lan17
lan17 deleted the fix/go-shadow-fill-and-value-with-error branch November 14, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants